package phoenix.web.page_objects;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.PageBaseWebExt;
import phoenix.core.config.extensions.ConfigExt;
import phoenix.core.data_models.UserProfileDataModel;
import phoenix.core.data_models.UserProfileDataModel.ProfileDetails;
import phoenix.web.locators.base.UserPageLocatorsBase;

/**
 * Class provides access to web elements and actions on User page
 */
public class UserPage extends PageBaseWebExt
{
	/**
	 * Initializes the UserPage
	 * @param p_manager
	 */
	public UserPage(PhoenixManager p_manager)
	{
		super(p_manager);
	}

	UserProfileDataModel profileModel = new UserProfileDataModel(manager);

	/**
	 * Gets web elements by site
	 * @return UserPageLocatorsBase instance
	 */
	public UserPageLocatorsBase elements()
	{
		switch (manager.testModel().getSiteName())
		{
			case ConfigExt.SITE_ID_CLICKANDFLIRT:
			{
				return new phoenix.web.locators.clickandflirt.UserPageLocators();
			}
			case ConfigExt.SITE_ID_LOCALSGOWILD:
			{
				return new phoenix.web.locators.localsgowild.UserPageLocators();
			}
			case ConfigExt.SITE_ID_EBONYFLIRT:
			{
				return new phoenix.web.locators.ebonyflirt.UserPageLocators();
			}
			case ConfigExt.SITE_ID_CHEECKYLOVERS:
			{
				return new phoenix.web.locators.cheekylovers.UserPageLocators();
			}
			case ConfigExt.SITE_ID_WILDBUDDIES:
			{
				return new phoenix.web.locators.wildbuddies.UserPageLocators();
			}
			case ConfigExt.SITE_ID_FLIRT:
			{
				return new phoenix.web.locators.flirt.UserPageLocators();
			}
			case ConfigExt.SITE_ID_FOREIGNGIRLFRIEND:
			{
				return new phoenix.web.locators.foreigngirlfriend.UserPageLocators();
			}
			case ConfigExt.SITE_ID_BENAUGHTY:
			{
				return new phoenix.web.locators.benaughty.UserPageLocators();
			}
			case ConfigExt.SITE_ID_MATUREDATING:
			{
				return new phoenix.web.locators.maturedating.UserPageLocators();
			}
			case ConfigExt.SITE_ID_NAUGHTYFEVER:
			{
				return new phoenix.web.locators.naughtyfever.UserPageLocators();
			}
			default:
			{
				return null;
			}
		}
	}

	public void waitForPageLoad()
	{
		wd().waitForPresence(elements().blockScreenName, "Screen name block");
	}

	public void clickWink()
	{
		wd().waitForPresence(elements().btnWink, "Button wink");
		wd().click(elements().btnWink);
	}

	public void clickBannerLookingFor()
	{
		wd().waitForVisibility(elements().btnUpgradeCustom, "Banner button 'Upgrade'");
		wd().click(elements().btnUpgradeCustom);
	}

	public void clickUserPhoto()
	{
		wd().waitForPresence(elements().imgUserProfilePhoto, "User Profile Photo");
		wd().click(elements().imgUserProfilePhoto);
	}

	public void clickUserAdditionalPhoto()
	{
		wd().waitForPresence(elements().btnMoreOnePhoto, "Button 'More One Photo'");
		wd().click(elements().btnMoreOnePhoto);
	}

	public void clickAddFriends()
	{
		wd().waitForPresence(elements().btnAddToFriends, "Button 'Add to friends'");
		wd().click(elements().btnAddToFriends);
	}

	public boolean isFriendsTextPresent()
	{
		return wd().isElementPresent(elements().btnAddToFriendsActivated);
	}

	public boolean isWinkedTextPresent()
	{
		return wd().isElementPresent(elements().btnWinkActivated);
	}

	public String getScreenname()
	{
		log().info("Get screenname");

		wd().waitForPresence(elements().blockScreenName, "Block 'Screenname'");
		return wd().getText(elements().blockScreenName);
	}

	public String getAge()
	{
		log().info("Get age");

		wd().waitForPresence(elements().blockAge, "Block 'Age'");
		return wd().getText(elements().blockAge).substring(0, 2).trim();
	}

	public String getLocation()
	{
		log().info("Get location");

		wd().waitForPresence(elements().blockLocation, "Block 'Location'");

		if (manager.isFlirt() || manager.isNF() || manager.isMD())
		{
			return wd().getText(elements().blockLocation).substring(0, 7);
		}

		return wd().getText(elements().blockLocation);
	}

	public String getHeight()
	{
		log().info("Get height");

		wd().waitForPresence(elements().blockHeight, "Block 'Height'");
		return wd().getText(elements().blockHeight);
	}

	public String getWeight()
	{
		log().info("Get weight");

		wd().waitForPresence(elements().blockWeight, "Block 'Weight'");
		return wd().getText(elements().blockWeight);
	}

	public String getBodyType()
	{
		log().info("Get body type");

		wd().waitForPresence(elements().blockBodyType, "Block 'Body type'");
		return wd().getText(elements().blockBodyType);
	}

	public String getEyesColor()
	{
		log().info("Get eyes color");

		wd().waitForPresence(elements().blockEyeColor, "Block 'Eyes color'");
		return wd().getText(elements().blockEyeColor);
	}

	public String getHairColor()
	{
		log().info("Get hair color");

		wd().waitForPresence(elements().blockHairColor, "Block 'Hair color'");
		return wd().getText(elements().blockHairColor);
	}

	public String getPiercing()
	{
		log().info("Get piercing");

		wd().waitForPresence(elements().blockPiercing, "Block 'Piercing'");
		return wd().getText(elements().blockPiercing);
	}

	public String getTattoo()
	{
		log().info("Get tattoo");

		wd().waitForPresence(elements().blockTattoos, "Block 'Tattoo'");
		return wd().getText(elements().blockTattoos);
	}

	public String getOrientation()
	{
		log().info("Get orientation");

		wd().waitForPresence(elements().blockOrientation, "Block 'Orientation'");
		return wd().getText(elements().blockOrientation);
	}

	public String getMaritalStatus()
	{
		log().info("Get marital status");

		wd().waitForPresence(elements().blockMaritalStatus, "Block 'Marital status'");
		return wd().getText(elements().blockMaritalStatus);
	}

	public String getChildren()
	{
		log().info("Get children");

		wd().waitForPresence(elements().blockChildren, "Block 'Children'");
		return wd().getText(elements().blockChildren);
	}

	public String getIncome()
	{
		log().info("Get income");

		wd().waitForPresence(elements().blockIncome, "Block 'Income'");
		return wd().getText(elements().blockIncome);
	}

	public String getSmoke()
	{
		log().info("Get smoke");

		wd().waitForPresence(elements().blockSmoke, "Block 'Smoke'");
		return wd().getText(elements().blockSmoke);
	}

	public String getDrink()
	{
		log().info("Get drink");

		wd().waitForPresence(elements().blockDrink, "Block 'Drink'");
		return wd().getText(elements().blockDrink);
	}

	public String getEthnicOrigin()
	{
		log().info("Get ethnic origin");

		wd().waitForPresence(elements().blockEthnicOrigin, "Block 'Ethnic origin'");
		return wd().getText(elements().blockEthnicOrigin);
	}

	public String getReligion()
	{
		log().info("Get religion");

		wd().waitForPresence(elements().blockReligion, "Block 'Religion'");
		return wd().getText(elements().blockReligion);
	}

	public String getEducation()
	{
		log().info("Get education");

		wd().waitForPresence(elements().blockEducation, "Block 'Education'");
		return wd().getText(elements().blockEducation);
	}

	public String getLiving()
	{
		log().info("Get living");

		wd().waitForPresence(elements().blockLiving, "Block 'Living'");
		return wd().getText(elements().blockLiving);
	}

	public ProfileDetails getPersonalInfo()
	{
		ProfileDetails p_details = profileModel.new ProfileDetails();

		p_details.height = this.getHeight();
		p_details.weight = this.getWeight();
		p_details.bodyType = this.getBodyType();
		p_details.eyesColor = this.getEyesColor();
		p_details.hairColor = this.getHairColor();
		p_details.pircing = this.getPiercing();
		p_details.tattoo = this.getTattoo();
		p_details.orientation = this.getOrientation();
		p_details.maritalStatus = this.getMaritalStatus();
		p_details.children = this.getChildren();
		p_details.income = this.getIncome();
		p_details.smoke = this.getSmoke();
		p_details.drink = this.getDrink();
		p_details.ethnicOrigin = this.getEthnicOrigin();
		p_details.religion = this.getReligion();
		p_details.education = this.getEducation();
		p_details.living = this.getLiving();

		return p_details;
	}

	public String getLookingGender()
	{
		log().info("Get looking gender");

		wd().waitForPresence(elements().blockLookingGender, "Block 'Looking gender'");

		if (manager.isNF())
		{
			if (wd().getText(elements().blockLookingGender).equals("A man"))
			{
				return "male";
			}

			return "female";
		}

		return wd().getText(elements().blockLookingGender).toLowerCase();
	}

	public String getLookingAgeFrom()
	{
		log().info("Get looking age from");

		wd().waitForPresence(elements().blockLookingAge, "Block 'Looking age'");
		return wd().getText(elements().blockLookingAge).substring(0, 2);
	}

	public String getLookingAgeTo()
	{
		log().info("Get looking age to");

		wd().waitForPresence(elements().blockLookingAge, "Block 'Looking age'");

		if (manager.isNF())
		{
			return wd().getText(elements().blockLookingAge).substring(5);
		}

		return wd().getText(elements().blockLookingAge).substring(3);
	}

	public String getLookingLocation()
	{
		log().info("Get looking location");

		wd().waitForPresence(elements().blockLookingLocation, "Block 'Looking location'");
		return wd().getText(elements().blockLookingLocation).substring(14);
	}

	public String getLookingDistance()
	{
		log().info("Get looking distance");

		wd().waitForPresence(elements().blockLookingDistance, "Block 'Looking distance'");
		return wd().getText(elements().blockLookingDistance).substring(0, 2);
	}

	public void clickLinkVipInSearch()
	{
		log().info("Click link vip in search");

		wd().waitForPresence(elements().linkVipInSearch, "link 'Vip in search'");
		wd().click(elements().linkVipInSearch);
	}

	public void clickLinkInvisibleMode()
	{
		log().info("Click link invisible mode");

		wd().waitForPresence(elements().linkInvisibleMode, "link 'Invisible mode'");
		wd().click(elements().linkInvisibleMode);
	}

	public void clickLinkHotUser()
	{
		log().info("Click link hot user");

		wd().waitForPresence(elements().linkHotUser, "link 'Hot user'");
		wd().click(elements().linkHotUser);
	}

	public void clickLinkFreeCommunication()
	{
		log().info("Click link free communication");

		wd().waitForPresence(elements().linkFreeCommunication, "link 'Free communication'");
		wd().click(elements().linkFreeCommunication);
	}

	/**
	 * MD related
	 */
	public void clickLookingForBlock()
	{
		wd().waitForPresence(elements().btnEditLookingForInfo, "Block Looking for");
		wd().click(elements().btnEditLookingForInfo);
	}

	public void clickPersonalInfoBlock()
	{
		wd().waitForPresence(elements().btnEditPersonalInfo, "Block Personal Info");
		wd().click(elements().btnEditPersonalInfo);
	}
}
